<% content_for :left_sidebar do  %>
  <%= render :partial => "layouts/sidebar/xiwenguanli" %>
<% end %>
<%- model_class = News -%>
<div class="page-header">
  <h1>新闻稿件列表</h1>
</div>

<%= form_tag admins_news_index_path,:method => :get do %>
    <table class="search_table">
      <tr>
        <td>稿件类型:
        	 <% if (current_user.admin? || current_user.xiaobao?||current_user.waixuan? )  %>
        	   <%= select_tag :news_type,options_for_select([['我的稿件',1],['平台稿件',2]],session[:news_type]) %>
        	   <% else %>
        	    <%= select_tag :news_type,options_for_select([['我的稿件',1]],session[:news_type]) %>
        	 <% end %>
        

        作者:
        <%= text_field_tag :news_writer,session[:news_writer] %>
        栏目:
        <%=select_tag(:category_id, options_from_collection_for_select(@categories, "id", "cataname",session[:category_id]), prompt: '请选择') %>
        <% if session[:children_id] && @children_cates  %>
              <%=select_tag(:children_id, options_from_collection_for_select(@children_cates, "id", "cataname",session[:children_id]), prompt: '请选择') %>
        <% else  %>
              <select name='children_id' id="children_id" value="<%= session[:children_id] %>">
              </select>
        <% end %>
          专题:
          <%= text_field_tag :news_sptitle,session[:news_sptitle] %>
        </td>

      </tr>
      <tr>
        <td>稿件状态:

        <%= select_tag :news_check,options_for_select([['--请选择--',nil]] + News::CHECK.to_a,session[:news_check]) %>
        发布时间:
        <%= text_field_tag :news_begin,session[:news_begin],:class => 'datepicker' %>~
        <%= text_field_tag :news_end,session[:news_end],:class => 'datepicker' %>
        
        <script type="text/javascript">
          $(document).ready(function(){
            $('.datepicker').datepicker({
                format: 'yyyy-mm-dd'
            });
          });
        </script>
          ID:
          <%= text_field_tag :news_id,session[:news_id] %>
        </td>
        
      </tr>
      <tr>
      		<td>来稿单位:
        	  <%= select_tag(:department, options_from_collection_for_select(@departments, "id", "name"), prompt: '请选择')   %>
        	</td></tr>
      <tr>
        <td colspan="6">
          <%= select_button %>
          <%= new_button url: new_admins_news_path %>
        </td>
      </tr>
    </table>
<% end %>


<table class="table table-striped">

  <thead>
    <tr>
      <th>ID</th>
      <th>栏目</th>
      <th style="width: 230px;">主标题</th>
      <th>新增时间</th>
      <th>审核时间</th>
      <th style="width: 100px;"> 发稿人</th>
      <th style="width: 100px;">来稿单位</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
  </thead>


  <tbody>
    <% @news.each do |news| %>
      <tr>
        <td><%= link_to news.id, admins_news_path(news) %></td>
        <td><%= news.category.cataname if  news.category %></td>
        <td><%= link_to truncate(news.title.gsub("&nbsp;"," ").gsub("&#8226;","•"),:length => 30),news_path(news),:target => '_blank' %></td>
        <td><%= (news.commitime ? news.created_at : news.created_at).strftime('%Y/%m/%d %H:%M:%S') rescue nil %></td>
        <td><%= news.pubtime.strftime('%Y/%m/%d %H:%M:%S') rescue nil %></td>
        <td><%= news.postby %></td>
        <td><%= news.contribution_units %></td>
        <td>
          <% if news.check == 0 && news.toback_count <= 0 %>
            <%= news.check_text %>
          <% else %>
              <a href="<%= approve_detail_admins_news_path(news) %>" style="text-decoration:none;color: #000000;">
                  <span class="aprroved_span"><%= news.aprroved_count || '0' %></span>
                  <span class="toback_span"><%= news.toback_count || '0' %></span>
              </a>
          <% end %>
        </td>
        <td>
          <% if News.can_edit?(news,@current_user)|| check_shenhe(news.id) %>
            
            <% if ( ( !current_user.admin? && !check_shenhe_pass(news.id)) || current_user.admin? )  %>
              <%= link_to "编辑",edit_admins_news_path(news),:class => 'btn btn-default btn-xs' %>
             <%end%>
             
              <%if check_shenhe_back(news.id) && news.postby == current_user.name %>
                 <%= link_to '确认审核',confirm_check_admins_news_path(news), 'data-confirm'=>'确认送审？',:class => 'btn btn-info btn-xs' %>
              <%end %>
              <% if ( ((news.toback_count == 0 && !current_user.admin?) && !check_shenhe(news.id)) || current_user.admin?)  %>
                  <%= link_to "删除",admins_news_path(news),
                              :method => :delete,
                              :data => { :confirm => '确定删除?' },
                              :class => 'btn btn-xs btn-danger' %>
              <% end %>
          <% end %>
          <% if News.can_approve?(news,@current_user) %>
              <%if check_shenhe_role(news.id)==2 %>
             <span style="color: red;">已退稿</span>
                  <%else %>
            <%= link_to "审核",admins_news_path(news),:class => 'btn btn-info btn-xs' %>
                  <%end %>
          <% end %>
          <% if news.check == 0 && !news.admin_approved? %>
              <%= link_to "送审",admins_news_path(news),:class => 'btn btn-info btn-xs' %>
          <% end %>
          <%if current_user.admin? %>

                <%=link_to '修改发布时间',"javascript:void(0)",onclick:'change_time(this)' %>
                 <%=link_to '阅读量',"javascript:void(0)",onclick:'change_hits(this)' %>
                 <%= link_to (news.enable ? '可见':'不可见') ,change_enable_admins_news_path(news), 'data-confirm'=>'确认修改？',:class => ((news.enable ? 'btn btn-warning btn-xs':'btn btn-danger btn-xs') ) %>
          <%end %>
          <div class="change_time" style="display:none;position: absolute;
                  margin-top: -100px;
                  margin-left: 80px;
                  border: 1px solid gray;
                  padding: 5px;
                  background: white;" >

            <%= form_for(:news,url:change_time_admins_news_path(news), method:'post') do%>
                <span>输入新时间<input  type="text" name="new_time"  onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" readonly/></span><br/>
                <input type="button"  name="btn" onclick="submit_it(this)" value="修改" />
            <% end %>
             </div>
             
             <div class="change_hits" style="display:none;position: absolute;
                  margin-top: -100px;
                  margin-left: 80px;
                  border: 1px solid gray;
                  padding: 5px;
                  background: white;" >

            <%= form_for(:news,url:change_hits_admins_news_path(news), method:'post') do%>
                <span>输入点击数<input  type="text" name="new_hits"  /></span><br/>
                <input type="button"  name="btn" onclick="submit_it(this)" value="修改" />
            <% end %>
          </div>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= paginate @news %> <br><p>共计<%= @news_count %>条</p>
<script src="/My97DatePicker/WdatePicker.js"></script>
<script>

function submit_it(obj){
   var name =$(obj).parent().find("input[name=new_time]").val();
       $(obj).parent().submit();
}
  function change_time(obj){
      var ct =$(obj).parent().find(".change_time");

      if(ct.css('display')=='none'){
          $(".change_time").hide();
          ct.show();
      }else
      {
          ct.hide();
      }

  }
  
    function change_hits(obj){
      var ct =$(obj).parent().find(".change_hits");

      if(ct.css('display')=='none'){
          $(".change_hits").hide();
          ct.show();
      }else
      {
          ct.hide();
      }

  }
</script>